package ink.tiptop.utils;

import com.trilead.ssh2.Connection;
import com.trilead.ssh2.SCPClient;
import lombok.extern.slf4j.Slf4j;

import java.io.File;
import java.io.IOException;

@Slf4j
public class FileUtils {


    public static boolean uploadFileToSftp(Connection conn, String localFile, String remoteDir) {
        SCPClient scpClient = null;
        try {
            scpClient = conn.createSCPClient();
            scpClient.put(localFile, remoteDir);
//            log.info("拷贝文件:{},到{}成功",localFile,remoteDir);
        } catch (IOException e) {
            log.error(e.getMessage(), e);
            log.info("拷贝文件异常:远程路径:{}可能不存在", remoteDir);
            return false;
        }
        return true;
    }


    static void list(File f, int lv) {
        File[] childs = f.listFiles();
        for (int i = 0; i < childs.length; i++) {
            for (int j = 0; j < lv; j++)
                System.out.print(" ┃");
            if (i == childs.length - 1)
                System.out.println(" ┗-" + childs[i].getName());
            else
                System.out.println(" ┣-" + childs[i].getName());
            if (childs[i].isDirectory())
                list(childs[i], lv + 1);
        }
    }
}
